<template>
    <header>
        <div class="l-content">
            <el-button plain icon="el-icon-menu" size="mini" @click="handleMenu"></el-button>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :class="isDefaultActive === item.path ? 'active' : '' " @click.native="cleckBreadcrumb(item)" v-for="item in tags" :to="{ path: item.path }" :key="item.path">{{ item.label }}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="r-content">
            <el-dropdown szie="mini" trigger="click">
                <span class="person">
                    <img class="user" :src="userImg">
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>个人中心</el-dropdown-item>
                    <el-dropdown-item @click.native="logOut">退出登录</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </header>
</template>

<style lang="less" scoped>
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}

.l-content {
    display: flex;
    align-items: center;
    height: 30px;

    .el-button {
        margin-right: 20px;
    }

    h3 {
        color: #fff;
        text-align: center;
        line-height: 30px;
        margin: 0;
    }

    /deep/ .el-breadcrumb {
        &__item {
            &.active{
                .el-breadcrumb__inner {
                    color: #fff!important;
                }
            }
            &:last-child {
                .el-breadcrumb__inner {
                    color: rgba(255, 255, 255, .6);
                }
            }
        }

        &__inner.is-link {
            color: rgba(255, 255, 255, .6);
        }
    }
}

.r-content {

    .user {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }
}
</style>

<script>
import { mapState } from 'vuex';
export default {
    name: "CommonHeader",
    data() {
        return {
            userImg: require('../assets/images/portrait.jpg')
        };
    },
    methods: {
        handleMenu() {
            this.$store.commit('collapseMenu')
        },
        cleckBreadcrumb(item){
            this.$store.commit('isDefaultActive',item)
        },
        logOut(){
            this.$store.commit('clearToken');
            this.$store.commit('clearMenu');
            this.$router.push('/login')
        }
    },
    watch: {
        isDefaultActive: {
            handler(){
            },
            deep: true
        }
    },
    computed: {
        ...mapState({
            tags: state => state.tab.tabsList
        }),
        isDefaultActive(){
            return this.$store.state.tab.defaultActive;
        }
    }
};
</script>
